﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductTypesCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductTypesCommandHandlers
{
    public class ShowProductTypesCommandHandler : IRequestHandler<ShowProductTypesCommand, ApiResult<List<ProductTypes>>>
    {
        IBaseRepository<ProductTypes> Products;

        public ShowProductTypesCommandHandler(IBaseRepository<ProductTypes> Products)
        {
            this.Products = Products;
        }

        public async Task<ApiResult<List<ProductTypes>>> Handle(ShowProductTypesCommand request, CancellationToken cancellationToken)
        {
            var list = Products.GetAll().ToList();
            return new ApiResult<List<ProductTypes>>
            {
                Code = ApiEnum.success,
                Message = "Get all product types successfully",
                Data = list
            };
        }
    }
}
